<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居相关函数($$)*/

!defined('Q_PATH') && exit;

class Jiaju_Extend{

	/**
	 * 缓存函数
	 */
	public static function cacheShop($nId){
		$arrDir=C::getDisDir($nId);
		$arrDatas=Q::cache('shop_'.$arrDir[1].'_'.md5($arrDir[0]),'',
			array('encoding_filename'=>false,
				'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
			)
		);
		
		// 缓存商铺首页数据
		if($arrDatas===false){
			$arrDatas=Jiaju_Cacheshop::cacheIndex($nId);
		}
		
		return $arrDatas;
	}
	
	public static function cacheShopservices($nId){
		$arrDir=C::getDisDir($nId);
		$arrDatas=Q::cache('shopservices_'.$arrDir[1].'_'.md5($arrDir[0]),'',
			array('encoding_filename'=>false,
				'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
			)
		);
		
		// 缓存商铺服务数据
		if($arrDatas===false){
			$arrDatas=Jiaju_Cacheshop::cacheServices($nId);
		}
		
		return $arrDatas;
	}
	
	public static function cacheShopverify($nId){
		$arrDir=C::getDisDir($nId);
		$arrDatas=Q::cache('shopverify_'.$arrDir[1].'_'.md5($arrDir[0]),'',
			array('encoding_filename'=>false,
				'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
			)
		);
		
		// 缓存商铺证书数据
		if($arrDatas===false){
			$arrDatas=Jiaju_Cacheshop::cacheVerify($nId);
		}
		
		return $arrDatas;
	}
	
	public static function cacheShopbanner($nId){
		$arrDir=C::getDisDir($nId);
		$arrDatas=Q::cache('shopbanner_'.$arrDir[1].'_'.md5($arrDir[0]),'',
			array('encoding_filename'=>false,
				'cache_path'=>WINDSFORCE_PATH.'/~@~/data/jiaju/shop/'.$arrDir[0]
			)
		);
		
		// 缓存商铺广告数据
		if($arrDatas===false){
			$arrDatas=Jiaju_Cacheshop::cacheBanner($nId);
		}
		
		return $arrDatas;
	}
	
	public static function getThemePreview(){
		$arrData=array();
		$arrThemes=C::listDir(WINDSFORCE_PATH.'/System/app/jiaju/Theme/Default/shop');
		foreach($arrThemes as $sTheme){
			$arrData[$sTheme]=(array)include(WINDSFORCE_PATH.'/System/app/jiaju/Theme/Default/shop/'.$sTheme.'/public/info.php');
		}
		return $arrData;
	}
	
	public static function getTemplate($arrCompany,$sModule=ACTION_NAME,$bFull=false){
		if($arrCompany['jiajucompany_isfvip']==1 && is_file(TEMPLATE_PATH.'/shop/'.$arrCompany['jiajucompanyvip_template'].'/'.$sModule.'.html')){
			$sTemplate=$arrCompany['jiajucompanyvip_template'];
		}else{
			$sTemplate='default';
		}
		
		return ($bFull===true?TEMPLATE_PATH.'/':'').'shop/'.$sTemplate.'/'.$sModule.($bFull===true?'.html':'');
	}
	
	public static function getLogo($sLogo){
		if($sLogo){
			return Attachment_Extend::getPrefix().$sLogo;
		}else{
			return __ROOT__.'/System/app/jiaju/Static/Images/logo.png';
		}
	}
	
	public static function getBanner($sBanner){
		return Attachment_Extend::getPrefix().$sBanner;
	}
	
	public static function getCase($sImage){
		if($sImage){
			return Attachment_Extend::getPrefix().$sImage;
		}else{
			return __ROOT__.'/System/app/jiaju/Static/Images/case.png';
		}
	}

	public static function getEvent($sImage){
		if($sImage){
			return Attachment_Extend::getPrefix().$sImage;
		}else{
			return __ROOT__.'/System/app/jiaju/Static/Images/event.png';
		}
	}

	public static function getPackage($sImage,$nDefault=1,$nIndex=0){
		if($sImage){
			return Attachment_Extend::getPrefix().$sImage;
		}else{
			return __ROOT__.'/System/app/jiaju/Static/Images/package/'.$nDefault.'/bg/'.$nIndex.'.jpg';
		}
	}

	public static function getBuild($sImage){
		if($sImage){
			return Attachment_Extend::getPrefix().$sImage;
		}else{
			return '';
		}
	}

	public static function getCompanyList($nDistrict=null,$nHomeClass=null,$nBusinessClass=null,$nCommunityId=null,$nStyleId=null,$nPage=null,$bFull=true){
		$nDistrict===null && $nDistrict=intval(Q::G('did','G'));
		$nHomeClass===null && $nHomeClass=intval(Q::G('hid','G'));
		$nBusinessClass===null && $nBusinessClass=intval(Q::G('bid','G'));
		$nCommunityId===null && $nCommunityId=intval(Q::G('cid','G'));
		$nStyleId===null && $nStyleId=intval(Q::G('sid','G'));
		$nPage===null && $nPage=intval(Q::G('page','G'));

		$sUrl="[D]~@jiaju://company/{$nDistrict}-{$nHomeClass}-{$nBusinessClass}-{$nCommunityId}-{$nStyleId}-{$nPage}";
		if($bFull===true){
			return Q::U($sUrl);
		}else{
			return $sUrl;
		}
	}

	public static function getCaseList($nSpace=null,$nStyle=null,$nPrice=null,$nArea=null,$nPage=null,$bFull=true){
		$nSpace===null && $nSpace=intval(Q::G('spid','G'));
		$nStyle===null && $nStyle=intval(Q::G('stid','G'));
		$nPrice===null && $nPrice=intval(Q::G('pid','G'));
		$nArea===null && $nArea=intval(Q::G('aid','G'));
		$nPage===null && $nPage=intval(Q::G('page','G'));

		$sPrefix='[D]~@';
		if(MODULE_NAME==='cases' && ACTION_NAME==='index' && $GLOBALS['_citysitesub_real_']=='www'){
			$sPrefix='www~@';
		}
		
		$sUrl="{$sPrefix}jiaju://cases/{$nSpace}-{$nStyle}-{$nPrice}-{$nArea}-{$nPage}";
		if($bFull===true){
			return Q::U($sUrl);
		}else{
			return $sUrl;
		}
	}

	public static function getEventList($nPage=null,$bFull=true){
		$nPage===null && $nPage=intval(Q::G('page','G'));

		$sUrl="[D]~@jiaju://events_{$nPage}/index";
		if($bFull===true){
			return Q::U($sUrl);
		}else{
			return $sUrl;
		}
	}
	
	public static function getBiddingList($nPage=null,$bFull=true){
		$nPage===null && $nPage=intval(Q::G('page','G'));

		$sUrl="[D]~@jiaju://biddings_{$nPage}/index";
		if($bFull===true){
			return Q::U($sUrl);
		}else{
			return $sUrl;
		}
	}

	public static function getShopUrl($arrCompany,$bFull=true){
		if(APP_NAME==='admin' || APP_NAME==='myadmin'){
			$GLOBALS['_commonConfig_']['URL_MODEL']=2;
			$GLOBALS['_commonConfig_']['DOMAIN_ON']=true;
			$GLOBALS['_commonConfig_']['DOMAIN_TOP']='114.ms';
		}
		
		if($arrCompany['jiajucompany_isfvip']==1){
			$sDomain=$arrCompany['jiajucompany_domain'].'.vip';
		}else{
			$sDomain=$arrCompany['jiajucompany_id'].'.so';
		}
		if($bFull===true){
			$sDomain=Q::U_($sDomain);
			if(APP_NAME==='admin' || APP_NAME==='myadmin'){
				$GLOBALS['_commonConfig_']['URL_MODEL']=0;
			}
			return $sDomain;
		}else{
			return $sDomain;
		}
	}

	public static function getUrl($arrCompany,$sType,$sAction='index',$bFull=true){
		$sUrl=self::getShopUrl($arrCompany,false)."~@jiaju://{$sType}/{$sAction}";
		if($bFull===true){
			$sUrl=Q::U($sUrl);
			if(APP_NAME==='admin' || APP_NAME==='myadmin'){
				$GLOBALS['_commonConfig_']['URL_MODEL']=0;
			}
			if(APP_NAME==='admin'){
				$sUrl=str_replace('/user/url/admin.php/','/',$sUrl);
			}
			if(APP_NAME==='myadmin'){
				$sUrl=str_replace('/user/url/my.php/','/',$sUrl);
			}
			return $sUrl;
		}else{
			return $sUrl;
		}
	}
	
	public static function getOrderUrl($arrCompany){
		return self::getUrl($arrCompany,'order');
	}
	
	public static function getMapUrl($arrCompany){
		return self::getUrl($arrCompany,'map');
	}
	
	public static function getAboutUrl($arrCompany){
		return self::getUrl($arrCompany,'about');
	}

	public static function getServicesUrl($arrCompany){
		return self::getUrl($arrCompany,'services');
	}

	public static function getContactUrl($arrCompany){
		return self::getUrl($arrCompany,'contact');
	}
	
	public static function getHonorUrl($arrCompany){
		return self::getUrl($arrCompany,'honor');
	}
	
	public static function getBusinessUrl($arrCompany){
		return self::getUrl($arrCompany,'business');
	}
	
	public static function getCommentUrl($arrCompany){
		return self::getUrl($arrCompany,'comment');
	}
	
	public static function getAddcommentUrl($arrCompany){
		return self::getUrl($arrCompany,'addcomment');
	}
	
	public static function getCommentpageUrl($arrCompany){
		return self::getUrl($arrCompany,'comment_{page}','index',false);
	}
	
	public static function getGuestbookUrl($arrCompany){
		return self::getUrl($arrCompany,'guestbook');
	}
	
	public static function getAddguestbookUrl($arrCompany){
		return self::getUrl($arrCompany,'addguestbook');
	}
	
	public static function getGuestbookpageUrl($arrCompany){
		return self::getUrl($arrCompany,'guestbook_{page}','index',false);
	}

	public static function getCredit($nCredit){
		return $nCredit;
	}
	
	public static function getCaseUrl($arrCompany){
		return self::getUrl($arrCompany,'case');
	}
	
	public static function getCaseShow($arrCompany,$nCaseId){
		return self::getUrl($arrCompany,'case-'.$nCaseId);
	}
	
	public static function getCasepageUrl($arrCompany){
		return self::getUrl($arrCompany,'case_{page}','index',false);
	}

	public static function getBuildUrl($arrCompany){
		return self::getUrl($arrCompany,'build');
	}
	
	public static function getBuildShow($arrCompany,$nVisitId){
		return self::getUrl($arrCompany,'build-'.$nVisitId);
	}
	
	public static function getBuildpageUrl($arrCompany){
		return self::getUrl($arrCompany,'build_{page}','index',false);
	}

	public static function getRoomUrl($arrCompany){
		return self::getUrl($arrCompany,'room');
	}
	
	public static function getRoomShow($arrCompany,$nCaseId){
		return self::getUrl($arrCompany,'room-'.$nCaseId);
	}
	
	public static function getRoompageUrl($arrCompany){
		return self::getUrl($arrCompany,'room_{page}','index',false);
	}

	public static function getVideoUrl($arrCompany){
		return self::getUrl($arrCompany,'video');
	}
	
	public static function getVideoShow($arrCompany,$nCaseId){
		return self::getUrl($arrCompany,'video-'.$nCaseId);
	}
	
	public static function getVideopageUrl($arrCompany){
		return self::getUrl($arrCompany,'video_{page}','index',false);
	}

	public static function getPackageUrl($arrCompany){
		return self::getUrl($arrCompany,'package');
	}
	
	public static function getPackageShow($arrCompany,$nCaseId){
		return self::getUrl($arrCompany,'package-'.$nCaseId);
	}
	
	public static function getPackagepageUrl($arrCompany){
		return self::getUrl($arrCompany,'package_{page}','index',false);
	}

	public static function getEventUrl($arrCompany){
		return self::getUrl($arrCompany,'event');
	}
	
	public static function getEventShow($arrCompany,$nEventId){
		return self::getUrl($arrCompany,'event-'.$nEventId);
	}

	public static function getEventpageUrl($arrCompany){
		return self::getUrl($arrCompany,'event_{page}','index',false);
	}
	
	public static function getTeamShow($arrCompany,$nUserId){
		return self::getUrl($arrCompany,'team-'.$nUserId);
	}
	
	public static function getTeamUrl($arrCompany){
		return self::getUrl($arrCompany,'team');
	}
	
	public static function getDiaryUrl($arrCompany){
		return self::getUrl($arrCompany,'diary');
	}

	public static function getDiarypageUrl($arrCompany){
		return self::getUrl($arrCompany,'diary_{page}','index',false);
	}
	
	public static function getAnliUrl($arrCompany){
		return self::getUrl($arrCompany,'anli');
	}
	
	public static function getAnlipageUrl($arrCompany){
		return self::getUrl($arrCompany,'anli_{page}','index',false);
	}

	public static function getDesignerType($nType){
		$arrType=array(0=>'设计师',1=>'高级设计师',2=>'金牌设计师',3=>'首席设计师');
		return isset($arrType[$nType])?$arrType[$nType]:'';
	}

	public static function getBuildProgress($nBuild){
		$arrProgress=array(0=>'开工准备中',1=>'开工大吉',2=>'水电改造',3=>'泥瓦工阶段',4=>'木工阶段',5=>'油漆阶段',6=>'安装阶段',7=>'验收完成');
		return isset($arrProgress[$nBuild])?$arrProgress[$nBuild]:'';
	}

	public static function getOrderType($nType){
		$arrType=array(0=>'未指定',1=>'申请设计',2=>'申请报价',3=>'申请设计和报价',4=>'申请报价设计和施工',5=>'申请监理',6=>'申请免费验房',7=>'申请装修套餐服务');
		return isset($arrType[$nType])?$arrType[$nType]:'';
	}
	
	public static function getBiddingWay($nWay){
		$arrWay=array(0=>'不限',1=>'半包',2=>'全包',3=>'清包');
		return isset($arrWay[$nWay])?$arrWay[$nWay]:'';
	}
	
	public static function getShoprankUrl(){
		return Q::U('jiaju://shoprank/index');
	}

	public static function getShoplevelUrl(){
		return Q::U('jiaju://shoplevel/index');
	}
	
	public static function getFreeroomUrl(){
		return Q::U('jiaju://freeroom/index');
	}

	public static function getFreedesignUrl(){
		return Q::U('jiaju://freedesign/index');
	}

	public static function getFreerateUrl(){
		return Q::U('jiaju://freerate/index');
	}
	
	public static function getFreeplanUrl(){
		return Q::U('jiaju://freeplan/index');
	}
	
	public static function getFree5qualityUrl(){
		return Q::U('jiaju://free5quality/index');
	}
	
	public static function getFreethreeUrl(){
		return Q::U('jiaju://freethree/index');
	}

	public static function getFreesoftdesignUrl(){
		return Q::U('jiaju://freesoftdesign/index');
	}

	public static function getAdvpaymentUrl(){
		return Q::U('jiaju://advpayment/index');
	}

	public static function getSatispaymentUrl(){
		return Q::U('jiaju://satispayment/index');
	}
	
	public static function getCpverifyUrl(){
		return Q::U('jiaju://cp-verify/index');
	}

	public static function getConsumerverifyUrl(){
		return Q::U('jiaju://cs-verify/index');
	}
	
	public static function getRealverifyUrl(){
		return Q::U('jiaju://rl-verify/index');
	}
	
	public static function getVipUrl(){
		return Q::U('jiaju://vip/index');
	}

	public static function getAdUrl(){
		return Q::U('jiaju://ad/index');
	}
	
	public static function getJoinUrl(){
		return Q::U('jiaju://join/index');
	}
	
	public static function getJobUrl(){
		return Q::U('jiaju://job/index');
	}

	public static function getScore($nScore){
		$nScore=round(abs($nScore-3)/3,2)*100;
		if($nScore!=0){
			$nScore.='%';
		}
		return $nScore;
	}
	
	public static function getShopscoreUrl(){
		return Q::U('jiaju://shopscore/index');
	}

	public static function getBiddingUrl($nBiddingId){
		return Q::U('[D]~@jiaju://bidding-'.$nBiddingId.'/index');
	}

	public static function getBuildOrder($arrCompany,$nBuildId){
		return self::getUrl($arrCompany,'buildorder_'.$nBuildId);
	}

	public static function getXue($cat){
		$arrXue=array(
			15=>'zhuangxiu',16=>'zhuangxiu-liucheng',2=>'zhuangxiu-gonglue',17=>'zhuangxiu-zhishi',3=>'zhuangxiu-fengshui',
			12=>'linggan',18=>'linggan-chaoliu',7=>'linggan-mingren',6=>'linggan-jiaju',
			9=>'dapei',19=>'dapei-anli',5=>'dapei-peishi',20=>'dapei-xiaochangshi',21=>'dapei-diy',
			22=>'chanpin',23=>'chanpin-dzjiaju',24=>'chanpin-pinpai',25=>'chanpin-jiancaidaogou',26=>'chanpin-baoyang',
			27=>'chanpin-jiancai',28=>'chanpin-jiayong',29=>'chanpin-daogou',30=>'chanpin-shipin',
			32=>'other',31=>'baodao',14=>'boy',1=>'girl',
		);

		if(!Core_Extend::isPostInt($cat)){
			$nResult=array_search($cat,$arrXue);
			return $nResult?$nResult:0;
		}else{
			return isset($arrXue[$cat])?$arrXue[$cat]:'';
		}
	}
	
	public static function getBaike($cat){
		$arrBaike=array(
			1810=>'liucheng',1811=>'zhishi',1812=>'fengshui',1813=>'zhuangxiu',
			1814=>'jiancai',1815=>'yu',1816=>'zhiwu',1817=>'dianqi'
		);

		if(!Core_Extend::isPostInt($cat)){
			$nResult=array_search($cat,$arrBaike);
			return $nResult?$nResult:0;
		}else{
			return isset($arrBaike[$cat])?$arrBaike[$cat]:'';
		}
	}

	public static function getNew($cat){
		$arrNew=array(
			1818=>'shichang',1819=>'guoji',1820=>'zhiliang',1821=>'zhanhui',
			1822=>'sheji',1823=>'pinpai',1824=>'chuangyi',1825=>'xiaohui',
			1826=>'weiyi',1827=>'haodian',1828=>'fangtan',1829=>'xinwen',
			1830=>'topic',1831=>'xinpin',1808=>'hunjia',1807=>'hufu',
			1806=>'caizhuang',1805=>'faxing',1804=>'fengxiong',1803=>'jianfei',
			1802=>'zhengxing',1801=>'fushi',1834=>'yule',1747=>'jiankang',
			1746=>'shenghuo',1748=>'xingzuo',1833=>'qinzi',1749=>'meishi',
			1750=>'qiche',1751=>'qiwenqushi',1753=>'tuku',1832=>'anli',
		);

		if(!Core_Extend::isPostInt($cat)){
			$nResult=array_search($cat,$arrNew);
			return $nResult?$nResult:0;
		}else{
			return isset($arrNew[$cat])?$arrNew[$cat]:'';
		}
	}

	public static function getPhotoList($nSpace=null,$nStyle=null,$nSite=null,$nPage=null,$bFull=true){
		$nSpace===null && $nSpace=intval(Q::G('spid','G'));
		$nStyle===null && $nStyle=intval(Q::G('stid','G'));
		$nSite===null && $nSite=intval(Q::G('site_id','G'));
		$nPage===null && $nPage=intval(Q::G('page','G'));

		$sUrl="photo~@jiaju://photo/{$nSpace}-{$nStyle}-{$nSite}-{$nPage}";
		if($bFull===true){
			return Q::U($sUrl);
		}else{
			return $sUrl;
		}
	}

}
